package cn.com.css.taxInspection.workflow.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;
import java.util.List;

import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.gt3.entity.JcAjxxEntity;
import cn.com.css.taxInspection.gt3.service.JcAjxxService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.workflow.entity.WorkflowLogConfirmEntity;
import cn.com.css.taxInspection.workflow.service.WorkflowLogConfirmService;

/**
 * ${comments}
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-03-22 15:03:26
 */
@Controller
@RequestMapping("/workflow/log")
public class WorkflowLogConfirmController {
	@Autowired
	private WorkflowLogConfirmService workflowLogConfirmService;
	@Autowired
	private HttpSessionService httpSessionService;
	
	@Autowired
	private JcAjxxService jcAjxxService;
	
	
	@SuppressWarnings("unchecked")
	@ApiOperation(value = "查询分页数据(待确认)")
	@PostMapping("/confirmList")
	// @RequiresPermissions("workflowLogConfirm:list")
	@ResponseBody
	@DS("oracle")
	public DataResult findListByPage(@RequestBody WorkflowLogConfirmEntity workflowLogConfirm) {
		String currentUserId = httpSessionService.getCurrentUserId();
		@SuppressWarnings("rawtypes")
		Page page = new Page(workflowLogConfirm.getPage(), workflowLogConfirm.getLimit());
		LambdaQueryWrapper<WorkflowLogConfirmEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		queryWrapper.like(WorkflowLogConfirmEntity::getTaxpeople,currentUserId);
		queryWrapper.isNull(WorkflowLogConfirmEntity::getIsConfirm);
		IPage<WorkflowLogConfirmEntity> iPage = workflowLogConfirmService.page(page, queryWrapper);
		List<WorkflowLogConfirmEntity> records = iPage.getRecords();
		for (WorkflowLogConfirmEntity entity : records) {
			String relevance = entity.getRelevance();
			JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
			String nsrmc = jcAjxxEntity.getNsrmc();
			String nsrsbh = jcAjxxEntity.getNsrsbh();
			 entity.setNsrmc(nsrmc);
			 entity.setNsrsbh(nsrsbh);
		}
		return DataResult.success(iPage);
	}
	
	
	@SuppressWarnings("unchecked")
	@ApiOperation(value = "查询分页数据(已确认)")
	@PostMapping("/confirmList1")
	// @RequiresPermissions("workflowLogConfirm:list")
	@ResponseBody
	@DS("oracle")
	public DataResult findListByPage1(@RequestBody WorkflowLogConfirmEntity workflowLogConfirm) {
		String currentUserId = httpSessionService.getCurrentUserId();
		@SuppressWarnings("rawtypes")
		Page page = new Page(workflowLogConfirm.getPage(), workflowLogConfirm.getLimit());
		LambdaQueryWrapper<WorkflowLogConfirmEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		queryWrapper.like(WorkflowLogConfirmEntity::getTaxpeople,currentUserId);
		queryWrapper.isNotNull(WorkflowLogConfirmEntity::getIsConfirm);
		IPage<WorkflowLogConfirmEntity> iPage = workflowLogConfirmService.page(page, queryWrapper);
		List<WorkflowLogConfirmEntity> records = iPage.getRecords();
		for (WorkflowLogConfirmEntity entity : records) {
			String relevance = entity.getRelevance();
			JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
			String nsrmc = jcAjxxEntity.getNsrmc();
			String nsrsbh = jcAjxxEntity.getNsrsbh();
			 entity.setNsrmc(nsrmc);
			 entity.setNsrsbh(nsrsbh);
		}
		return DataResult.success(iPage);
	}
	
	
	@ApiOperation(value = "确认")
	@PostMapping("/confirm")
	// @RequiresPermissions("workflowLogConfirm:list")
	@ResponseBody
	@DS("oracle")
	public DataResult confirm(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
		String currentUserId = httpSessionService.getCurrentUserId();
		Date date = new Date();
		for (String id : ids) {
			WorkflowLogConfirmEntity workflowLogConfirm = workflowLogConfirmService.getById(id);
			workflowLogConfirm.setIsConfirm("1");
			workflowLogConfirm.setUpdateId(currentUserId);
			workflowLogConfirm.setUpdateTime(date);
			workflowLogConfirmService.updateById(workflowLogConfirm);
		}
		
		return DataResult.success();
	}

}
